package com.gator.desig_mode.itrator;



import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc
 */
public class InfoCollege implements Collage {


  private Department[] departments;

  private int position = 0;


  public InfoCollege() {
    //初始化10
    departments = new Department[5];
  }

  public InfoCollege(Department[] departments) {
    this.departments = departments;
  }


  @Override
  public String getName() {
    return departments[position].getName();
  }

  @Override
  public void addDepartMent(String name, String desc) {
    if (position >= departments.length) {

      System.out.println("容量已满....");

      return;
    }
    System.out.println("信息学院添加元素----系");
    departments[position] = new Department(name, desc);

    position++;
  }

  @Override
  public Iterator createIterator() {
    return new InfoCollageIterator(departments);
  }
}


class ComputerCollege implements Collage {

  List<Department> list;

  public ComputerCollege(){
    list = new ArrayList<>();
  }

  @Override
  public String getName() {
    return null;
  }

  @Override
  public void addDepartMent(String name, String desc) {
    list.add(new Department(name,desc));

  }

  @Override
  public Iterator createIterator() {
    return new ComputerCollageIterator(list);
  }
}
